class UserNameException extends Exception {

}

class PassWordException extends Exception {

}

class Login {

    //实现登录过程
    private String username = "kkk";
    private String password = "123456";

    public void login(String username,String password) throws UserNameException, PassWordException {
        if (!username.equals(this.username)) {
//            System.out.println("用户名错误！");
//            return;

                throw new UserNameException();
        }
        if (!password.equals(this.password)) {
//            System.out.println("密码错误！");
//            return;
            throw new PassWordException();
        }
        System.out.println("登录成功！");
    }

}

public class Demo7 {
    public static void main(String[] args) {
        Login login = new Login();
        try {
            login.login("kkkk","1234");
        } catch (UserNameException e) {
            System.out.println("用户名错误");
        } catch (PassWordException e) {
            System.out.println("密码错误");
        }
    }
}
